﻿using markdown_picture_packer.common.constants;
using markdown_picture_packer.common.utils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace markdown_picture_packer.frontend.panels
{
    public class LogTextPanel : BasePanel
    {
        private Label Lb;
        private RichTextBox Rtb;
        public LogTextPanel() { }
        public override void InitComponent()
        {
            Lb = new Label { Text = "日志", Font = Constants.EXECUTE_FONT, TextAlign = ContentAlignment.MiddleLeft };
            Rtb = new RichTextBox { Multiline = true, WordWrap = true, AcceptsTab = true, BackColor = Color.White, ScrollBars = RichTextBoxScrollBars.Vertical };
        }
        public override void InitSize(int newWdith, int newHeight)
        {
            Lb.Size = new Size(newWdith, Constants.EXECUTE_LINE_HEIGHT);
            Rtb.Size = new Size(newWdith, FrontUtil.GetFillHeight(newHeight, Lb));
        }
        public override void InitLocation()
        {
            Lb.Location = new Point(0, 0);
            FrontUtil.OnBottom(Rtb, Lb, 0);
        }
        public override void AddComponent()
        {
            Controls.Add(Lb);
            Controls.Add(Rtb);
        }
        //向富文本添加有颜色的文字
        public void AppendColoredText(string text, Color color)
        {
            Rtb.SelectionStart = Rtb.TextLength;
            Rtb.SelectionLength = 0;
            Rtb.SelectionColor = color;
            Rtb.AppendText(text);
            Rtb.SelectionColor = Rtb.ForeColor;
            Rtb.AppendText(Environment.NewLine);
        }
    }
}
